<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               :page="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
                   plain
                   v-if="permission.murderControl_delete"
                   @click="handleDelete">删 除
        </el-button>
      </template>
      <template slot-scope="{row}" slot="menu">
        <el-button type="text"
                   icon="el-icon-user-solid"
                   size="small"
                   plain
                   style="border: 0;background-color: transparent !important;"
                   @click.stop="handleDataSub1(row)">嫌疑人
        </el-button>
        <el-button type="text"
                   icon="el-icon-user"
                   size="small"
                   plain
                   style="border: 0;background-color: transparent !important;"
                   @click.stop="handleDataSub2(row)">受害人
        </el-button>
      </template>
      
    </avue-crud>
    <el-dialog :title="嫌疑人" append-to-body :visible.sync="subVisible" :direction="direction"
                width="80%">
      <basic-container>
        <avue-crud :option="optionSub"
                   :data="dataSub"
                   :page="pageSub"
                   v-model="formSub"
                   :table-loading="loadingSub"
                   ref="crudSub"
                   @row-del="rowDelSub"
                   @row-update="rowUpdateSub"
                   @row-save="rowSaveSub"
                   :before-open="beforeOpenSub"
                   @search-change="searchChangeSub"
                   @search-reset="searchResetSub"
                   @selection-change="selectionChangeSub"
                   @current-change="currentChangeSub"
                   @size-change="sizeChangeSub"
                   @on-load="onLoadSub">
          <template slot="menuLeft">
            <el-button type="danger"
                       size="small"
                       icon="el-icon-delete"
                       plain
                       @click="handleDeleteSub">删 除
            </el-button>
          </template>
        </avue-crud>
      </basic-container>
    </el-dialog>
    <el-dialog :title="受害人" append-to-body :visible.sync="subVisible2" :direction="direction"
               width="80%" >
      <basic-container>
        <avue-crud :option="optionSub2"
                   :data="dataSub2"
                   :page="pageSub2"
                   v-model="formSub2"
                   :table-loading="loadingSub2"
                   ref="crudSub2"
                   @row-del="rowDelSub2"
                   @row-update="rowUpdateSub2"
                   @row-save="rowSaveSub2"
                   :before-open="beforeOpenSub2"
                   @search-change="searchChangeSub2"
                   @search-reset="searchResetSub2"
                   @selection-change="selectionChangeSub2"
                   @current-change="currentChangeSub2"
                   @size-change="sizeChangeSub2"
                   @on-load="onLoadSub2">
          <template slot="menuLeft">
            <el-button type="danger"
                       size="small"
                       icon="el-icon-delete"
                       plain
                       @click="handleDeleteSub2">删 除
            </el-button>
          </template>
        </avue-crud>
      </basic-container>
    </el-dialog>
    <el-dialog title="选择坐标点"
      ref="gridDialog"
        append-to-body
        :visible.sync="mapBox"
        :fullscreen="false"
        style="width:100%;height:900px;">
      <coordinate-map style="height:600px;" v-on:getGridData="getGridMap($event)" :lngv="form.lng ? form.lng :''" :latv="form.lat ? form.lat :''" />
    </el-dialog>
  </basic-container>
</template>

<script>
  import {getList, getDetail, add, update, remove} from "@/api/ninebasic/societySecurity/murderControl";
  import {getList as getListSub, getDetail as getDetailSub, add as addSub, update as updateSub, remove as removeSub} from "@/api/ninebasic/societySecurity/murderSuspect";
  import {getList as getListSub2, getDetail as getDetailSub2, add as addSub2, update as updateSub2, remove as removeSub2} from "@/api/ninebasic/societySecurity/murderVictim";
  import {mapGetters} from "vuex";
   import {cardid} from "@/util/validate";
  //打点坐标组件
  import coordinateMap from '@/components/gis/coordinateMap'
  export default {
    data() {
      //校验身份正号码
      const validateCardid = (rule, value, callback) => {
        if(cardid(value)[0]){
          callback(new Error(cardid(value)[1]))
        }else{
          callback();
        }
      };
      return {
        mapBox: false,
        form: {},
        query: {},
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        selectionList: [],
        option: {
           height: 'auto',
          calcHeight: 30,
          dialogWidth: 850,
          tip: false,
          searchShow: true,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          excelBtn: true,
          dialogClickModal: false,
          menuWidth:350,
          column: [
            {
              label: "所属网格",
              prop: "gridId",
              type: "tree",
              span: 24,
              //multiple: true,
              parent: true,
              display: true,
              
              dicMethod: "get",
              dicUrl: "/api/smart-system/dept/treeByPid",
              props: {
                label: "title"
              
              },
              checkStrictly: true,
              //slot: true,
              search: true,
              rules: [{
                required: true,
                message: "请输入所属网格",
                trigger: "click"
              }],
            },
            
            {
              label: "案件名称",
              prop: "caseName",
              type: "input",
              search: true,
              overHidden: true,
              rules: [{
                required: true,
                message: "请输入案件名称",
                trigger: "blur"
              }],
            },
            {
              label: "案件编号",
              prop: "caseCode",
              type: "input",
              search: true,
              overHidden: true,
              rules: [{
                required: true,
                message: "请输入案件编号",
                trigger: "blur"
              }],
            },
           
             {
              label: "发生日期",
              prop: "startDate",
              type: "date",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              hide: true,
              rules: [{
                required: true,
                message: "请输入案件发生日期",
                trigger: "blur"
              }],
            },
            
             {
              label: "侦查终结日期",
              prop: "endDate",
              type: "date",
              format: "yyyy-MM-dd",
              valueFormat: "yyyy-MM-dd",
              hide: true,
            },
            {
              label: "简要情况",
              prop: "briefSituation",
              type: "textarea",
              span: 24,
              hide: true,
            },
            {
              label: "经度",
              prop: "lng",
              type: "input",
              hide: true,
              suffixIcon:'el-icon-map-location',
              props: {
                label: "lng",
                value: ""
              },
              // rules: [{
              //   required: false,
              //   message: "请选择坐标点",
              //   trigger: "click"
              // }],
              click:()=>{
                this.openGrid()
              }
            },
            {
              label: "纬度",
              prop: "lat",
              type: "input",
              hide: true,
              suffixIcon:'el-icon-map-location',
              props: {
                label: "lat",
                value: ""
              },
              // rules: [{
              //   required: false,
              //   message: "请选择坐标点",
              //   trigger: "click"
              // }],
              click:()=>{
                this.openGrid()
              }
            },
            {
              label: "备注",
              prop: "remark",
              type: "input",
              addDisplay: false,
              editDisplay: false,
              viewDisplay: false,
              hide: true,
            },
           
          ]
        },
        data: [],
        subVisible: false,
        direction: 'rtl',
        murderControlId: 0,
        murderControlName: "命案防控",
        formSub: {},
        querySub: {},
        loadingSub: true,
        dataSub: [],
        selectionListSub: [],
        pageSub: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        optionSub: {
          height: 600,
          calcHeight: 30,
          dialogWidth: '80%',
          tip: false,
          searchShow: false,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          excelBtn: false,
          dialogClickModal: false,
              column: [
                {
                  label: "主键id",
                  prop: "id",
                  type: "input",
                  addDisplay: false,
                  editDisplay: false,
                  viewDisplay: false,
                  hide: true,
                },
                {
                  label: "案件id",
                  prop: "caseId",
                  type: "input",
                  addDisplay: false,
                  editDisplay: false,
                  viewDisplay: false,
                  hide: true,
                },
                {
                  label: "案件编号",
                  prop: "caseCode",
                  type: "input",
                  addDisplay: false,
                  editDisplay: false,
                  viewDisplay: false,
                  hide: true,
                },
                {
                  label: "证件代码",
                  prop: "cardCode",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=certificate_code",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入证件代码",
                    trigger: "blur"
                  }],
                },
                {
                  label: "证件号码",
                  prop: "idCard",
                  type: "input",
                  rules: [{
                    required: true,
                    validator: validateCardid,
                    trigger: "blur"
                  }],
                  blur: ({value}) => {
                    //this.$message.success(value,column)
                    this.formSub.birthday  = value.substring(6,10)+"-"+value.substring(10,12)+"-"+value.substring(12,14);
                    this.formSub.sex = value.substring(16,17)%2===0?'2':'1';
                  }
                },
                {
                  label: "姓名",
                  prop: "name",
                  type: "input",
                  rules: [{
                    required: true,
                    message: "请输入姓名",
                    trigger: "blur"
                  }],
                },
                {
                  label: "曾用名",
                  prop: "nameUsedBefore",
                  type: "input",
                  hide: true,
                },
                {
                  label: "性别",
                  prop: "sex",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=sex",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  rules: [{
                    required: true,
                    message: "请输入性别",
                    trigger: "blur"
                  }],
                },
                {
                  label: "出生日期",
                  prop: "birthday",
                  type: "date",
                  format: "yyyy-MM-dd",
                  valueFormat: "yyyy-MM-dd",
                  rules: [{
                    required: true,
                    message: "请输入出生日期",
                    trigger: "blur"
                  }],
                },
                {
                  label: "国籍（地区）",
                  prop: "nationality",
                  type: "input",
                  hide: true,
                },
                {
                  label: "民族",
                  prop: "nation",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=nation",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                },
                {
                  label: "籍贯",
                  prop: "nativePlace",
                  type: "input",
                  hide: true,
                },
                {
                  label: "婚姻状况",
                  prop: "marriage",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=marital_status",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                },
                {
                  label: "政治面貌",
                  prop: "politics",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=party",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                },
                {
                  label: "学历",
                  prop: "education",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=education",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                },
                {
                  label: "宗教信仰",
                  prop: "religion",
                  type: "select",
                  dicUrl: "/api/smart-system/dict/dictionary?code=religion",
                  props: {
                    label: "dictValue",
                    value: "dictKey"
                  },
                  hide: true,
                },
                {
                  label: "职业类别",
                  prop: "professionType",
                  type: "input",
                  hide: true,
                },
                {
                  label: "职业",
                  prop: "profession",
                  type: "input",
                },
                {
                  label: "服务处所",
                  prop: "serviceSpace",
                  type: "input",
                },
                {
                  label: "户籍地",
                  prop: "householdAddr",
                  type: "input",
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入户籍地",
                    trigger: "blur"
                  }],
                },
                {
                  label: "户籍门(楼)详址",
                  prop: "householdAddrDetail",
                  type: "input",
                  span: 12,
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入户籍门(楼)详址",
                    trigger: "blur"
                  }],
                },
                {
                  label: "现住地",
                  prop: "liveAddr",
                  type: "input",
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入现住地",
                    trigger: "blur"
                  }],
                },
                {
                  label: "现住门(楼)详址",
                  prop: "liveAddrDetail",
                  type: "input",
                  span: 12,
                  rules: [{
                    required: true,
                    message: "请输入现住门(楼)详址",
                    trigger: "blur"
                  }],
                },
                {
                  label: "是否为严重精神障碍患者",
                  prop: "isPsychosis",
                  type: "select",
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入是否为严重精神障碍患者",
                    trigger: "blur"
                  }],
                  dicData:[
                    {
                      label: "是",
                      value: "1",
                    },
                    {
                      label: "否",
                      value: "0",
                    },
                  ],
                },
                {
                  label: "是否为未成年人",
                  prop: "isJuvenile",
                  type: "select",
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入是否为未成年人",
                    trigger: "blur"
                  }],
                   dicData:[
                    {
                      label: "是",
                      value: "1",
                    },
                    {
                      label: "否",
                      value: "0",
                    },
                  ],
                },
                {
                  label: "是否为青少年",
                  prop: "isYoungster",
                  type: "select",
                  hide: true,
                  rules: [{
                    required: true,
                    message: "请输入是否为青少年",
                    trigger: "blur"
                  }],
                   dicData:[
                    {
                      label: "是",
                      value: "1",
                    },
                    {
                      label: "否",
                      value: "0",
                    },
                  ],
                },
                
              ]
          },
        //受害人
        subVisible2: false,
        formSub2: {},
        querySub2: {},
        loadingSub2: true,
        dataSub2: [],
        selectionListSub2: [],
        pageSub2: {
          pageSize: 10,
          currentPage: 1,
          total: 0
        },
        optionSub2: {
           height: 'auto',
          calcHeight: 30,
          dialogWidth: 950,
          tip: false,
          searchShow: false,
          searchMenuSpan: 6,
          border: true,
          index: true,
          viewBtn: true,
          selection: true,
          excelBtn: false,
          dialogClickModal: false,
            column: [
              {
                label: "主键id",
                prop: "id",
                type: "input",
                addDisplay: false,
                editDisplay: false,
                viewDisplay: false,
                hide: true,
              },
              {
                label: "案件id",
                prop: "caseId",
                type: "input",
                addDisplay: false,
                editDisplay: false,
                viewDisplay: false,
                hide: true,
              },
              {
                label: "案件编码",
                prop: "caseCode",
                type: "input",
                addDisplay: false,
                editDisplay: false,
                viewDisplay: false,
                hide: true,
              },
              {
                label: "证件代码",
                prop: "cardCode",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=certificate_code",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
                rules: [{
                  required: true,
                  message: "请输入证件代码",
                  trigger: "blur"
                }],
              },
              {
                label: "证件号码",
                prop: "idCard",
                type: "input",
                rules: [{
                    required: true,
                    validator: validateCardid,
                    trigger: "blur"
                  }],
                  blur: ({value}) => {
                    //this.$message.success(value,column)
                    this.formSub2.birthday  = value.substring(6,10)+"-"+value.substring(10,12)+"-"+value.substring(12,14);
                    this.formSub2.sex = value.substring(16,17)%2===0?'2':'1';
                  }
              },
              {
                label: "姓名",
                prop: "name",
                type: "input",
                rules: [{
                  required: true,
                  message: "请输入姓名",
                  trigger: "blur"
                }],
              },
              {
                label: "性别",
                prop: "sex",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=sex",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                rules: [{
                  required: true,
                  message: "请输入性别",
                  trigger: "blur"
                }],
              },
              {
                label: "出生日期",
                prop: "birthday",
                type: "date",
                format: "yyyy-MM-dd hh:mm:ss",
                valueFormat: "yyyy-MM-dd hh:mm:ss",
                rules: [{
                  required: true,
                  message: "请输入出生日期",
                  trigger: "blur"
                }],
              },
              {
                label: "国籍(地区)",
                prop: "nationality",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=nationality",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "民族",
                prop: "nation",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=nation",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "籍贯",
                prop: "nativePlace",
                type: "input",
                hide: true,
              },
              {
                label: "婚姻状况",
                prop: "marriage",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=marital_status",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "政治面貌",
                prop: "politics",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=party",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "学历",
                prop: "education",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=education",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "宗教信仰",
                prop: "religion",
                type: "select",
                dicUrl: "/api/smart-system/dict/dictionary?code=religion",
                props: {
                  label: "dictValue",
                  value: "dictKey"
                },
                hide: true,
              },
              {
                label: "职业类别",
                prop: "professionType",
                type: "input",
                hide: true,
              },
              {
                label: "职业",
                prop: "profession",
                type: "input",
              },
              {
                label: "服务处所",
                prop: "serviceSpace",
                type: "input",
              },
              {
                label: "户籍地",
                prop: "householdAddr",
                type: "input",
                hide: true,
              },
              {
                label: "户籍门(楼)详址",
                prop: "householdAddrDetail",
                type: "input",
                span: 24,
                hide: true,
              },
              {
                label: "现住地",
                prop: "liveAddr",
                type: "input",
                hide: true,
              },
              {
                label: "现住门(楼)详址",
                prop: "liveAddrDetail",
                type: "input",
                span: 24,
              },
              
            ]
        },
      };
    },
     components:{
      coordinateMap
    },
    computed: {
      ...mapGetters(["permission"]),
      permissionList() {
        return {
          addBtn: this.vaildData(this.permission.murderControl_add, false),
          viewBtn: this.vaildData(this.permission.murderControl_view, false),
          delBtn: this.vaildData(this.permission.murderControl_delete, false),
          editBtn: this.vaildData(this.permission.murderControl_edit, false)
        };
      },
      ids() {
        let ids = [];
        this.selectionList.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      },
       subIds() {
        let ids = [];
        this.selectionListSub.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      },
       subIds2() {
        let ids = [];
        this.selectionListSub2.forEach(ele => {
          ids.push(ele.id);
        });
        return ids.join(",");
      }
    },
    methods: {
       //打开地图图层
        openGrid(){
        this.mapBox = true
      },

      //地图选择组件回调处理数据
      getGridMap(data){
        console.log("callback:",data)

        if(data){
          this.form.lng = data.lng
          this.form.lat = data.lat
        }

        this.mapBox = false
      },
      rowSave(row, done, loading) {
        add(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowUpdate(row, index, done, loading) {
        update(row).then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          done();
        }, error => {
          loading();
          window.console.log(error);
        });
      },
      rowDel(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDelete() {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return remove(this.ids);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crud.toggleSelection();
          });
      },
      beforeOpen(done, type) {
          //新增和修改页面，控制网格树加载职能选择末级，查询页面可以选择父级
        if (["edit", "add"].includes(type)) {
            const gridId = this.findObject(this.option.column,"gridId");
            gridId.parent = false;
           
        }
        if (["edit", "view"].includes(type)) {
          getDetail(this.form.id).then(res => {
            this.form = res.data.data;
          });
        }
        done();
      },
      searchReset() {
        this.query = {};
        this.onLoad(this.page);
      },
      searchChange(params, done) {
        this.query = params;
        this.page.currentPage = 1
        this.onLoad(this.page, params);
        done();
      },
      selectionChange(list) {
        this.selectionList = list;
      },
      selectionClear() {
        this.selectionList = [];
        this.$refs.crud.toggleSelection();
      },
      currentChange(currentPage){
        this.page.currentPage = currentPage;
      },
      sizeChange(pageSize){
        this.page.pageSize = pageSize;
      },
      refreshChange() {
        this.onLoad(this.page, this.query);
      },
      onLoad(page, params = {}) {
        this.loading = true;
        getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
          const data = res.data.data;
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;
          this.selectionClear();
        });
      },
      // 子表模块 嫌疑人
      handleDataSub1(row) {
        this.subVisible = true;
        this.caseId = row.id;
        this.caseCode = row.caseCode;
        this.onLoadSub(this.pageSub)
      },
      handleSubClose(hide) {
        hide();
      },
      rowSaveSub(row, loading, done) {
        row = {
          ...row,
        caseId : this.caseId,
        caseCode : this.caseCode
        };
        addSub(row).then(() => {
          loading();
          this.onLoadSub(this.pageSub);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          done();
          window.console.log(error);
        });
      },
      rowUpdateSub(row, index, loading, done) {
        row = {
          ...row,
        };
        updateSub(row).then(() => {
          loading();
          this.onLoadSub(this.pageSub);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          done();
          window.console.log(error);
        });
      },
      rowDelSub(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return removeSub(row.id);
          })
          .then(() => {
            this.onLoadSub(this.pageSub);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDeleteSub() {
        if (this.selectionListSub.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return removeSub(this.subIds);
          })
          .then(() => {
            this.onLoadSub(this.pageSub);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crudSub.toggleSelection();
          });
      },
      beforeOpenSub(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetailSub(this.formSub.id).then(res => {
            this.formSub = res.data.data;
          });
        }
        done();
      },
      searchResetSub() {
        this.querySub = {};
        this.onLoadSub(this.pageSub);
      },
      searchChangeSub(params) {
        this.querySub = params;
        this.onLoadSub(this.pageSub, params);
      },
      selectionChangeSub(list) {
        this.selectionListSub = list;
      },
      currentChangeSub(currentPage) {
        this.pageSub.currentPage = currentPage;
      },
      sizeChangeSub(pageSize) {
        this.pageSub.pageSize = pageSize;
      },
      refreshChangeSub() {
        this.onLoadSub(this.page, this.query);
      },
      onLoadSub(page, params = {}) {
        this.loadingSub = true;
        const values = {
          ...params,
          caseId: this.caseId,
        }
        getListSub(page.currentPage, page.pageSize, Object.assign(values, this.querySub)).then(res => {
          const data = res.data.data;
          this.pageSub.total = data.total;
          this.dataSub = data.records;
          this.selectionListSub = [];
          this.loadingSub = false;
        });
      },
       // 子表模块 受害人
      handleDataSub2(row) {
        this.subVisible2 = true;
        this.caseId = row.id;
        this.caseCode = row.caseCode;
        this.onLoadSub2(this.pageSub2)
      },
      handleSubClose2(hide) {
        hide();
      },
      rowSaveSub2(row, loading, done) {
        row = {
          ...row,
          caseId: this.caseId,
          caseCode: this.caseCode,
        };
        addSub2(row).then(() => {
          loading();
          this.onLoadSub2(this.pageSub2);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          done();
          window.console.log(error);
        });
      },
      rowUpdateSub2(row, index, loading, done) {
        row = {
          ...row,
         
        };
        updateSub2(row).then(() => {
          loading();
          this.onLoadSub2(this.pageSub2);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        }, error => {
          done();
          window.console.log(error);
        });
      },
      rowDelSub2(row) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return removeSub2(row.id);
          })
          .then(() => {
            this.onLoadSub2(this.pageSub2);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      },
      handleDeleteSub2() {
        if (this.selectionListSub2.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return removeSub2(this.subIds2);
          })
          .then(() => {
            this.onLoadSub2(this.pageSub2);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.$refs.crudSub2.toggleSelection();
          });
      },
      beforeOpenSub2(done, type) {
        if (["edit", "view"].includes(type)) {
          getDetailSub2(this.formSub2.id).then(res => {
            this.formSub2 = res.data.data;
          });
        }
        done();
      },
      searchResetSub2() {
        this.querySub2 = {};
        this.onLoadSub2(this.pageSub2);
      },
      searchChangeSub2(params) {
        this.querySub = params;
        this.onLoadSub2(this.pageSub2, params);
      },
      selectionChangeSub2(list) {
        this.selectionListSub2 = list;
      },
      currentChangeSub2(currentPage) {
        this.pageSub2.currentPage = currentPage;
      },
      sizeChangeSub2(pageSize) {
        this.pageSub2.pageSize = pageSize;
      },
      refreshChangeSub2() {
        this.onLoadSub2(this.page, this.query);
      },
      onLoadSub2(page, params = {}) {
        this.loadingSub2 = true;
        const values = {
          ...params,
          caseId: this.caseId,
          caseCode: this.caseCode,
        }
        getListSub2(page.currentPage, page.pageSize, Object.assign(values, this.querySub2)).then(res => {
          const data = res.data.data;
          this.pageSub2.total = data.total;
          this.dataSub2 = data.records;
          this.selectionListSub2 = [];
          this.loadingSub2 = false;
        });
      },
    }
  };
</script>

<style>
.el-form-item__content{
   margin-left: 130px ! important;
}
.el-form-item__label {
  width: 130px ! important;
}
</style>
